package org.concepts.java.generics;

import org.junit.Test;

/**
 * 
 * @author vvvv
 *
 */
public class TestCarRepair {

  
  /**
   * Show that even for simple inheritance a user can get CCE that is only
   * manifested at runtime.
   */
  @Test(expected = ClassCastException.class)
  public void testRuntimeFailure() {
    Honda honda = new Honda();
    CarRepair carRepair = new CarRepair(honda);
    carRepair.changeOil();
    Ford car = (Ford) carRepair.getCar();
  }
  
  /**
   * Show that {@link CarRepairGenerics} helps catch error at compile time.
   */
  @Test
  public void testCompileError() {
    Honda honda = new Honda();
    CarRepairGenerics<Honda> carRepair = new CarRepairGenerics<Honda>(honda);
    carRepair.changeOil();
    
    //Following errors are caught at compile time.
    //Ford car = carRepair.getCar();
    //car = (Ford) carRepair.getCar();
    
    // Following works fine and we don't need to do any casting.
    Honda carHonda = carRepair.getCar();
  }

  
  
}
